package chat;

import java.awt.*;
import javax.swing.*;

class ChatWindow extends JPanel {

    final int wrows = 8;
    final int wcolumns = 25;
    JButton closeButton;
    JButton saveButton;
    JPanel panel;
    JTextArea writearea;
    JTextArea readarea;
    String windowLabel;

    ChatWindow(String label) {
        createButton();
        createWriteArea();
        createReadArea();
        createPanel();
        windowLabel = label;
    }

    void createButton() {
        closeButton = new JButton("Close");
        saveButton = new JButton("Save conversation");
    }

    void createReadArea() {
        readarea = new JTextArea(wrows * 3, wcolumns);
        readarea.setEditable(false);
    }

    void createWriteArea() {
        writearea = new JTextArea(wrows, wcolumns);
        writearea.setEditable(true);
    }

    void createPanel() {
        panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JScrollPane writescrollpane = new JScrollPane(writearea);
        JScrollPane readscrollpane = new JScrollPane(readarea);
        panel.add(readscrollpane, BorderLayout.NORTH);
        panel.add(writescrollpane, BorderLayout.CENTER);
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(2,1));
        buttonPanel.add(saveButton);
        buttonPanel.add(closeButton);
        panel.add(buttonPanel, BorderLayout.EAST);
        add(panel);
    }

}
